#include <cstdio>
#include <cassert>
#include <cuda_runtime.h>

int main() {
  float *a_d, *b_d;     // pointers to device memory
  int N = 14;
  int i;
  // allocate arrays on host
  float *a_h = new float[N];
  float *b_h = new float[N];
  // allocate arrays on device
  cudaMalloc(&a_d, sizeof(float)*N);
  cudaMalloc(&b_d, sizeof(float)*N);
  // initialize host data
  for (i=0; i<N; i++) {
    a_h[i] = 10.f+i;
    b_h[i] = 0.f;
  }
  // send data from host to device: a_h to a_d
  cudaMemcpy(a_d, a_h, sizeof(float)*N, cudaMemcpyHostToDevice);
  // copy data within device: a_d to b_d
  cudaMemcpy(b_d, a_d, sizeof(float)*N, cudaMemcpyDeviceToDevice);
  // retrieve data from device: b_d to b_h
  cudaMemcpy(b_h, b_d, sizeof(float)*N, cudaMemcpyDeviceToHost);
  // check result
  for (i=0; i<N; i++)
    assert(a_h[i] == b_h[i]);
  // cleanup
  delete a_h; delete b_h;
  cudaFree(a_d); cudaFree(b_d);
  return 0;
}
